<template>
	<view>
		<mh-navbar custom :back="true" title="设置" fixed center zIndex="1010" />
		<view class="container">
			<view class="item-list-wrap">
				<view class="item" @click="goUrl('/pages/mine/user_info')">
					<view class="left">
						个人信息
					</view>
					<view class="right">
						<image src="../../static/img/my/right.png" mode=""></image>
					</view>
				</view>
				<view style="height: 2px;"></view>
				<view class="item" @click="goUrl('/pages/mine/about')">
					<view class="left">
						关于我们
					</view>
					<view class="right">
						<image src="../../static/img/my/right.png" mode=""></image>
					</view>
				</view>
				<view style="height: 2px;"></view>
				<view class="item" @click="openModel('clean')">
					<view class="left">
						清除缓存
					</view>
					<view class="right">
						<view class="rightText">
							{{storageSize}}
						</view>
						<image src="../../static/img/my/right.png" mode=""></image>
					</view>
				</view>
				<view style="height: 2px;"></view>
				<view style="height: 10px;"></view>
				<view class="item">
						<view class="logOut" @click="logout">
							<view>退出登录</view>
						</view>
				</view>
			</view>
		</view>
		<!-- 模态窗 -->
		<u-modal v-model="showModel" show-cancel-button :content="content" @confirm="confirm" :async-close="true"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				storageSize: '',
				// #ifdef APP-PLUS
				version: plus.runtime.version
				// #endif
			}
		},
		onLoad(){
			// #ifdef APP-PLUS
			this.getStorageSize()
			// #endif
		},
		methods: {
			goUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
			confirm() {
				if (this.modelType == 'clean') {
					this.modelType = '';
					this.content = '';
					this.clearCache();
					this.showModel = false;
				} else if (this.modelType == 'logout') {
					this.showModel = false;
					try {
						uni.removeStorageSync('userInfo');
						uni.reLaunch({
							url: '../../login/login'
						})
					} catch (e) {
						// error
					}
				}
			},
			openModel(type) {
				this.modelType = type;
				if (this.modelType == 'clean') {
					this.content = '确定要清楚缓存吗？';
					this.showModel = true;
				} else if (this.modelType == 'logout') {
					this.content = '确定要退出当前账号吗？';
					this.showModel = true;
				}
			},
			logout() {
				this.$u.api.logout().then(res => {
					this.$u.toast(res.msg);
					if (res.code == '200') {
						uni.removeStorageSync('cacheData');
						uni.removeStorageSync('vuex_user');
						uni.removeStorageSync('vuex_token');
						let self = this;
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}, 500);
					}
				});
			}
		}
	}
</script>

<style lang="scss">
.logOut{
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
}
.container{
	.item-list-wrap{
		display: flex;
		flex-direction: column;
		.item{
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			height: 50px;
			background: #FFFFFF;
			padding: 0 10px;
			.left{
				
			}
			.right{
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				image{
					width: 20px;
					height: 20px;	
				}
			}
		}
	}
}
</style>
